package com.qf.zyh.services.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.zyh.common.ResponseResult;
import com.qf.zyh.common.ResultType;
import com.qf.zyh.dao.UserTokenMapper;
import com.qf.zyh.entity.UserToken;
import com.qf.zyh.services.TokenServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TokenServicesImpl implements TokenServices {
    @Autowired
    private UserTokenMapper userTokenMapper;

    @Override
    public ResultType table(Integer page, Integer limit, String accessToken) {
        PageHelper.startPage(page,limit);
        List<UserToken> list = userTokenMapper.selectByacc(accessToken);
        list.stream().forEach(System.out::println);
        PageInfo info = new PageInfo(list);
        return new ResultType(0,"",(int)info.getTotal(),info.getList());
    }

    @Override
    public ResponseResult delto(Integer[] ids) {
        userTokenMapper.delto(ids);
        return ResponseResult.getSuccess();
    }


    @Override
    public ResponseResult updateto(UserToken u) {
        int i = userTokenMapper.updateByPrimaryKeySelective(u);
        if (i>0) {
            return ResponseResult.getSuccess();
        }
        return ResponseResult.getFail("修改出错");
    }
}
